package pers.cz.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @program: PostGirl-panent
 * @description: 空闲处理
 * @author: Cheng Zhi
 * @create: 2022-10-05 00:02
 **/
public class IdleStateHandler extends ChannelInboundHandlerAdapter {

    /**
     * 一段时间没有向服务器写数据，则发送ping包
     **/
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleState state = ((IdleStateEvent) evt).state();
            if (state == IdleState.WRITER_IDLE) {
                // 如果写事件超时，这里要发送ping

            }
        } else {
            super.userEventTriggered(ctx, evt);
        }
    }
}
